
<style>
    .ui-dialog{z-index:1000;}
</style>

<?php include_once 'common/header.php'; ?>
<!-- admin_main -->
<div class="admin_main">
    <!-- Admin_top end -->
    <?php include_once 'common/borrow_left.php'; ?>
    <!-- Admin_Left End -->
    <div class="admin_right">
        <div class="admin_right_title">
            <strong>贷款管理</strong> &gt;&gt; 添加担保机构
        </div>
        <div class="admin_right_info">
            <div class="payonline_form">
                <form action="/ychadmin/guarantee/add/" method="post" id="gruaranteeForm"
                      name="gruaranteeForm" enctype="multipart/form-data" onSubmit="return subForm();">
                    <input  type="hidden" name="act" id="act" value="add"/>
                    <dl class="online_dl">
                        <dt>机构类型名称：</dt>
                        <dd>
                            <select name="type" id="type" onchange="changeType();">

                                <option value="0">请选择</option>
                                <?php foreach ($borrow_guarantee as $key => $val) { ?>
                                    <option value="<?php echo $key; ?>"><?php echo $val; ?></option>
                                <?php } ?>

                            </select>
                        </dd>
                    </dl>
                    <dl class="online_dl">
                        <dt>前台是否可选：</dt>
                        <dd>
                        <input type="checkbox" name="isActive" id="isActive" checked="true">
                        </dd>
                    </dl>

                    <dl class="online_dl">
                        <dt>机构名称：</dt>
                        <dd>
                            <input type="text" name="name" id="name" size="50"  value="" />
                        </dd>
                    </dl>
                    <dl class="online_dl">
                        <dt>机构别名：</dt>
                        <dd>
                            <input type="text" name="alias" id="alias" size="50"  value="" />
                        </dd>
                    </dl>
                    <dl class="online_dl">
                        <dt>注册资金：</dt>
                        <dd>
                            <input type="text" name="account" id="account" size="50"  value="" />
                            <span id="accountTip"></span>
                        </dd>
                    </dl>
                    <dl class="online_dl">
                        <dt>所属省市：</dt>
                        <dd>
                            <select name="province" id="province" onchange="changeCity(this.value, 'city');">
                                <option value="">请选择</option>
                            </select>
                            <select name="city" id="city" onchange="changeCity(this.value, 'area');"><option value="">请选择</option></select>
                        </dd>
                    </dl>
                    <dl class="online_dl">
                        <dt>详细地址：</dt>
                        <dd>
                            <textarea name="address" id="address" style="width:400px; height:50px;"></textarea>
                        </dd>
                    </dl>
                    <dl class="online_dl">
                        <dt>联系电话：</dt>
                        <dd>
                            <input type="text" name="contact" id="contact" size="50"  value="" />
                        </dd>
                    </dl>
                    <dl class="online_dl">
                        <dt>机构网址：</dt>
                        <dd>
                            <input type="text" name="web" id="web" size="50"  value="" />
                        </dd>
                    </dl>

                    <dl class="online_dl" style="height:110px;">
                        <dt>合作金融机构相关图片：</dt>
                        <dd>
                            <div class="mod">
                                <ul id="guarantee_att">
                                </ul>
                            </div>
                            <input type="hidden" id="att_id" name="att_id" />
                            <span id="logoimgTip"><a  href="javascript:;" onclick="add_att();" class="addtr">添加机构相关材料</a></span>
                        </dd>
                    </dl>
                    <br />
                    <dl class="online_dl">
                        <dt>公司成立日期：</dt>
                        <dd>
                            <input type="text" name="establishment_time" id="establishment_time" value="" onfocus="WdatePicker()" class="Wdate" style="z-index: 0;"/>
                        </dd>
                    </dl>
                    <br />
                    <dl class="online_dl">
                        <dt>开始合作时间：</dt>
                        <dd>
                            <input type="text" name="collaboration_time" id="collaboration_time" value="" onfocus="WdatePicker()" class="Wdate" style="z-index: 0;"/>
                        </dd>
                    </dl>
                    <br />
                    <dl class="online_dl">
                        <dt>机构简介：</dt>
                        <dd>
                            <script type="text/javascript" charset="utf-8" src="/static/ueditor/ueditor.config.js"></script>
                            <script type="text/javascript" charset="utf-8" src="/static/ueditor/ueditor.all.js"></script>
                            <script type="text/javascript" charset="utf-8">
                                var editor = new baidu.editor.ui.Editor();
                                editor.render('introduction');  //editor为编辑器容器的id
                            </script>
                            <textarea name="introduction" id="introduction" style="width:800px;">
                            </textarea>
                        </dd>
                    </dl>

                    <div id="fengxian" style="display:none;">
                        <dl class="online_dl" >
                            <dt>风险控制措施：</dt>
                            <dd>
                                <textarea name="risk_measures" id="risk_measures" style="width:800px; height:120px;"></textarea>
                            </dd>
                        </dl>
                        <dl class="online_dl">
                            <dt>抵押物信息：</dt>
                            <dd>
                                <textarea name="collateral" id="collateral" style="width:800px; height:120px;"></textarea>
                            </dd>
                        </dl>
                    </div>
                    <div id="baozhen" style="display:none;">
                        <dl class="online_dl">
                            <dt>保证函：</dt>
                            <dd>
                                <textarea name="letter_guarantee" id="letter_guarantee" style="width:800px; height:120px;"></textarea>
                            </dd>
                        </dl>
                    </div>
                    <div class="payment_btm">
                        <input type="submit" value="提交"  class="btn_b"/>
                    </div>
                </form>
            </div>


        </div>
    </div>
    <!-- Admin_Right End -->
</div>
<!-- admin_main end -->


<div class="user_list_con" id="grarantee_dialog" style="display:none;">
    <div id="grarantee_dialog_msg" style="text-align:center;color:red">&nbsp;</div>
    <iframe name="iframe" id="iframe" style="display:none;"></iframe>
    <form id="upload_form"  action="/ychadmin/guarantee/doupload"  enctype="multipart/form-data" method="post" target="iframe">
        <div class="user_right_border">
            <p style="color: red;">必须是本人 真实 有效的相关资料！（格式:jpg|png 最大:512K  最高:3000px  最宽:2048px） </p>
        </div>

        <div class="payonline_form">

            <dl class="online_dl" style="height:20px;">
                <dt>上传资料：</dt>
                <dd>
                    <input type="file" name="litpic" />
                </dd>
            </dl>
            <br />
            <dl class="online_dl" style="height:20px;">
                <dt>资料类型：</dt>
                <dd>
                    <select style="width: 160px;" name="type_id">
                        <option value="0">--请选择资料类型--</option>
                        <?php foreach ($type_list as $key => $val) { ?>
                            <option value="<?php echo $key; ?>"><?php echo $val; ?></option>
                        <?php } ?>
                    </select>
                </dd>
            </dl>
            <br />
            <dl class="online_dl" style="height:20px;">
                <dt>备注说明：</dt>
                <dd>
                    <textarea id="verify_remark" name="verify_remark" style="width: 400px;height: 150px;"></textarea>
                </dd>
            </dl>
        </div>
    </form>
</div>

<script type="text/javascript">

    function add_att() {
        $("#grarantee_dialog").dialog({
            width: 600,
            height: 400,
            modal: false, //蒙层（弹出会影响页面大小）
            title: '添加证明资料',
            buttons: {"提交": function () {
                    form_submit();
                }, "关闭": function () {
                    $(this).dialog("close");
                }}
        });
    }

    var att_arr = [];//定义一个数组
    function form_submit() {
        var options = {
            url: '/ychadmin/guarantee/doupload',
            clearForm: true,
            resetForm: true,
            beforeSubmit: checkForm,
            dataType: "json",
            type: "post",
            contentType: "multipart/form-data",
            success: function (ret) {

                if (ret.url == 'error') {
                    alert(ret.msg);
                } else {
                    $("#grarantee_dialog").dialog("close");
                    $("#guarantee_att").append('<li><a target="_blank" href="/' + ret.msg.litpic + '"><img src="/' + ret.msg.litpic + '" width="60" height="60"  /></a><h5>' + ret.msg.name + '</h5></li>');
                    att_arr.push(ret.msg.id);
                    $("#att_id").val(att_arr);
                }


            }
        };

        $("#upload_form").ajaxSubmit(options);
        return false;
    }

    function checkForm() {
        return true;
    }

    function subForm() {
        if ($('#alias').val() == '') {
            alert('机构别名不能为空');
            return false;

            if ($('#name').val() == '') {
                alert('担保机构名称不能为空');
                return false;
            } else if ($('#account').val() == '') {
                alert('注册资金不能为空');
                return false;
            } else if ($('#contact').val() == '') {
                alert('联系电话不能为空');
                return false;
            } else if ($('#web').val() == '') {
                alert('机构网址不能为空');
                return false;
            } else if ($('#address').val() == '') {
                alert('详细地址不能为空');
                return false;
            } else {
                return true;
            }
        }
    }

    $(document).ready(function () {
        getArea(0, '', 'province');
    });

    function changeType() {
        var type = $("#type").val()
        if (type == 3) {
            $("#baozhen").show();
            $("#fengxian").hide();
        } else {
            $("#fengxian").show();
            $("#baozhen").hide();
        }
    }

    function changeCity(a, obj) {
        var msg = "<option value=''>请选择</option>";
        if (a != '') {
            getArea(a, '', obj);
            if (obj == 'city') {
                $("#area").html(msg);
            }
        } else {
            if (obj == 'city') {
                $("#city").html(msg);
                $("#area").html(msg);
            }
        }

    }

    function getArea(pid, selected, obj) {
        $.ajax({
            type: "POST",
            url: "/area/get_option",
            data: "pid=" + pid + "&selected=" + selected,
            success: function (msg) {
                $("#" + obj).html(msg);
            },
            dataType: "text"
        });
    }

</script>
</body>
</html>
